package com.mtsmda.demo.spring.spring_core.run;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.mtsmda.demo.spring.spring_core.HelloWord;
import com.mtsmda.demo.spring.spring_core.looseCoupling.OutputHelper;

public class RunSpring {

	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"springCore.xml");
		e1(context);
		p();
		e2(context);
		p();
		e3(context);
	}

	private static void e3(ApplicationContext context) {
		OutputHelper xmlOutputHelper = (OutputHelper) context.getBean("jsonOG");
		xmlOutputHelper.generateOutput();
	}

	private static void e2(ApplicationContext context) {
		OutputHelper xmlOutputHelper = (OutputHelper) context
				.getBean("xmlOutputGenerator");
		xmlOutputHelper.generateOutput();
	}

	private static void e1(ApplicationContext context) {
		Object bean = context.getBean("helloBean");
		if (bean instanceof HelloWord) {
			HelloWord helloWord = (HelloWord) bean;
			System.out.println(helloWord.greeting());
			;
		}
	}

	private static void p() {
		System.out.println("\n ----- \n");
	}

}